//
//  UIBarButtonItem+LZFBarButtonItem.m
//  LZFBuDieJie
//
//  Created by 梁梓烽 on 16/6/21.
//  Copyright © 2016年 liangzifeng. All rights reserved.
//

#import "UIBarButtonItem+LZFBarButtonItem.h"

@implementation UIBarButtonItem (LZFBarButtonItem)

/**
 *  返回一个UIBarButtonItem
 *
 *  @param imageName       普通状态下的图片
 *  @param hightLightImage 高亮状态下的图片
 *  @param target          目标对象
 *  @param selector        响应方法
 *
 *  @return UIBarButtonItem
 */
+(UIBarButtonItem *)buttonItemWith:(NSString *)imageName highlightImage:(NSString *)hightLightImage target:(id)target selector:(SEL)selector
{
    UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
    [button sizeToFit];
    [button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:hightLightImage] forState:UIControlStateHighlighted];
    [button addTarget:target  action:selector forControlEvents:UIControlEventTouchUpInside];
    
    //解决按钮点击范围多大问题
    // 解决导航条按钮 点击范围过大的问题
    UIView *btnView = [[UIView alloc] initWithFrame:button.bounds];
    [btnView addSubview:button];
    
    
    return  [[UIBarButtonItem alloc]initWithCustomView:btnView];

}



/**
 *  返回一个UIBarButtonItem
 *
 *  @param imageName       普通状态下的图片
 *  @param hightLightImage selelcted状态下的图片
 *  @param target          目标对象
 *  @param selector        响应方法
 *
 *  @return UIBarButtonItem
 */
+(UIBarButtonItem *)buttonItemWith:(NSString *)imageName selectedImage:(NSString *)selectedImage target:(id)target selector:(SEL)selector
{
    UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
    [button sizeToFit];
    [button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:selectedImage] forState:UIControlStateSelected];
    [button addTarget:target  action:selector forControlEvents:UIControlEventTouchUpInside];
    
    //解决按钮点击范围多大问题
    // 解决导航条按钮 点击范围过大的问题
    UIView *btnView = [[UIView alloc] initWithFrame:button.bounds];
    [btnView addSubview:button];
    
    
    return  [[UIBarButtonItem alloc]initWithCustomView:btnView];
    
}



@end
